package cn.miju.admin.system.controller;

import cn.miju.admin.framework.model.BasePage;
import cn.miju.admin.system.service.DictService;
import cn.miju.admin.system.vo.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <pre>
 * 字典管理
 * </pre>
 *
 * @author zhuming
 * @version 1.0.0
 * @since 2023-04-06 16:25
 */
@RestController
@Api(tags = "系统-字典管理")
@ApiSort(6)
@RequestMapping("/system/dict")
public class DictController {
    private final DictService service;

    public DictController(DictService service) {
        this.service = service;
    }

    /**
     * 获取字典树
     * @return {@link List<DictTreeOutVO>}
     */
    @ApiOperation("获取字典树")
    @ApiOperationSupport(order = 1, author = "zhuming")
    @GetMapping("/tree")
    public List<DictTreeOutVO> getTree() {
        return service.getTree();
    }

    /**
     * 保存字典
     * @param inVO {@link DictSaveInVO}
     */
    @ApiOperation("保存字典")
    @ApiOperationSupport(order = 2, author = "zhuming")
    @PostMapping("/save")
    public void save(@RequestBody @Validated DictSaveInVO inVO) {
        service.save(inVO);
    }
    /**
     * 批量删除字典
     * @param inVO {@link DictDeleteInVO}
     */
    @ApiOperation("批量删除字典")
    @ApiOperationSupport(order = 3, author = "zhuming")
    @PostMapping("/deletes")
    public void deletes(@RequestBody @Validated DictDeleteInVO inVO) {
        service.deletes(inVO);
    }

    /**
     * 保存字典明细
     * @param inVO {@link DictSaveDetailInVO}
     */
    @ApiOperation("保存字典明细")
    @ApiOperationSupport(order = 4, author = "zhuming")
    @PostMapping("/saveDetail")
    public void saveDetail(@RequestBody @Validated DictSaveDetailInVO inVO) {
        service.saveDetail(inVO);
    }

    /**
     * 字典明细分页查询
     * @param inVO {@link DictDetailPageInVO}
     * @return {@link Page<DictDetailPageOutVO>}
     */
    @ApiOperation("字典明细分页查询")
    @ApiOperationSupport(order = 5, author = "zhuming")
    @GetMapping("/detailPage")
    public Page<DictDetailPageOutVO> getDetailPage(@ModelAttribute @Validated DictDetailPageInVO inVO) {
        return service.getDetailPage(inVO);
    }

    /**
     * 批量删除字典明细
     * @param inVO {@link DictDeleteInVO}
     */
    @ApiOperation("批量删除字典明细")
    @ApiOperationSupport(order = 6, author = "zhuming")
    @PostMapping("/detailDeletes")
    public void detailDeletes(@RequestBody @Validated DictDeleteInVO inVO) {
        service.detailDeletes(inVO);
    }
}
